package com.orange.oss.controller;

import com.orange.commonutils.result.Result;
import com.orange.oss.service.OssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author orange
 * @email orangestart@yeah.net
 * @create 2021-12-16 20:47
 */
@Api(tags = "阿里云oss文件上传")
@CrossOrigin
@RestController
@RequestMapping("/eduOss/fileOss")
public class OssController {

    @Autowired
    private OssService ossService;

    @ApiOperation("文件上传")
    @PostMapping("/upload")
    public Result uploadOssFile(
            @ApiParam("文件对象")
            @RequestParam("file")
                    MultipartFile file) {
        //获取上传到阿里云oss的url
        String url = ossService.upload(file);
        //返回Result对象
        return Result.ok().data("url", url).message("文件上传成功");
    }
}
